package com.xujc.controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * Created by xujc on 6/17/15.
 */
public class WelcomeAction extends ActionSupport {
    private String username;
    private String phone;
    private String email;
    private Integer age;
    private String error;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    public void validateTwo(){
        System.out.println("valid two");
        if (username == null || username.length()<1){
            addFieldError("username","输入用户名啊兄弟");
        }
        if (phone==null|| phone.length()<11||!phone.matches("[0-9]{11}")){
            addFieldError("phone","手机号要认真输入");
        }
        error="1";
    }

    public void validateThree(){
        if (age==null){
            addFieldError("age","输入年龄");
        }
        if (email==null||!phone.matches(".*@.*")){
            addFieldError("phone","邮箱不正确");
        }
        error="2";
    }

    public String one(){
        return "1";
    }

    public String two(){
        ActionContext.getContext().getSession().put("username",username);
        ActionContext.getContext().getSession().put("phone",phone);
        return  "2";
    }

    public String three(){
        ActionContext.getContext().getSession().put("email",email);
        ActionContext.getContext().getSession().put("age",age);
        return "3";
    }
}
